package net.shopxx.action.admin;

import java.io.IOException;

import javax.annotation.Resource;

import net.shopxx.bean.Pager;
import net.shopxx.entity.Refund;
import net.shopxx.entity.Refundnote;
import net.shopxx.service.MemberService;
import net.shopxx.service.RefundService;

import org.apache.struts2.convention.annotation.ParentPackage;

/**
 * 后台Action类 - 退款
 */

@ParentPackage("admin")
public class RefundAction extends BaseAdminAction {

	private static final long serialVersionUID = 229015918586548826L;

	private Refund refund;
	private Refundnote refundnote;
	private String processStatus;
	@Resource
	private MemberService memberService;
	@Resource
	private RefundService refundService;

	// 查看
	public String view() {
		refund = refundService.load(id);
		return VIEW;
	}

	// 列表
	public String list() {
		if(pager==null)
			pager=new Pager();
		pager.addWhereCluase("refundStatus", Refund.RefundStatus.platformed);
		pager = refundService.findByPager(pager);
		return LIST;
	}
	
	// 查看
	public String processSave() {

		Refund entity = refundService.load(id);
		entity.setProcessStatus(Enum.valueOf(Refund.ProcessStatus.class,
				processStatus));
		refundService.update(entity);
		redirectionUrl = "refund!view.action?id="+entity.getId();
		try {
			getResponse().sendRedirect(redirectionUrl);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public String savenote() {
		Refund entity = refundService.load(id);
		refundnote.setRefund(entity);
		refundnote.setMember(memberService.load(DEFAULTACCOUNT));
		entity.getRefundnoteSet().add(refundnote);
		refundService.update(entity);
		redirectionUrl = "refund!view.action?id="+entity.getId();
		try {
			getResponse().sendRedirect(redirectionUrl);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	// 删除
	public String delete() {
		try {
			refundService.delete(ids);
		} catch (Exception e) {
			return ajaxJsonErrorMessage("删除失败，会员数据被引用！");
		}
		return ajaxJsonSuccessMessage("删除成功！");
	}

	public Refund getRefund() {
		return refund;
	}

	public void setRefund(Refund refund) {
		this.refund = refund;
	}

	public String getProcessStatus() {
		return processStatus;
	}

	public void setProcessStatus(String processStatus) {
		this.processStatus = processStatus;
	}

	public Refundnote getRefundnote() {
		return refundnote;
	}

	public void setRefundnote(Refundnote refundnote) {
		this.refundnote = refundnote;
	}
	
	

}